@echo off
setlocal

:: config the jar path
set "JAR_FILE=device-application.jar"
set "JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -Dfile.encoding=UTF-8"

:: check if jar file exist
if not exist "%JAR_FILE%" (
    echo error: JAR file "%JAR_FILE%" not exist
    goto :END
)

:: check java command
java -version >nul 2>&1
if %ERRORLEVEL% neq 0 (
    echo error: java command not installed
    goto :END
)

:: start jar
echo start %JAR_FILE%...
java %JAVA_OPTS% -jar "%JAR_FILE%"

:: check start result
if %ERRORLEVEL% neq 0 (
    echo error : JAR start fail: %ERRORLEVEL%
    timeout /t 5 >nul  :: wait 5s then exit
) else (
    echo application exit
)

:END
endlocal

:: stop port
:: netstat -ano | findstr :<port>
:: taskkill /F /PID <pid>